﻿using System.ComponentModel.DataAnnotations;
using System.Web;
using System.Web.Mvc;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.IO;
using System.Text;

namespace DotaHelp.Models
{
    [MetadataType(typeof(Comment_Validate))]
    public partial class Comment
    {
        public string CommentText
        {
            get
            {
                return Text.StartsWith("News:", System.StringComparison.CurrentCultureIgnoreCase) ? Text.Remove(0, "News:".Length) : Text;
            }
        }
    }

    public class Comment_Validate
    {
        [Required(ErrorMessage = "Эй, а где комментарий?")]
        public string Text { get; set; }

        [Required(ErrorMessage = "Назовись!")]
        public string Author { get; set; }
    }


    [MetadataType(typeof(Guide_Validate))]
	public partial class Guide : IPublishItem
    {
        public GuidesText GuideText
        {
            get
            {
                if (!GuidesTexts.Any())
                {
                    GuidesTexts.Add(new GuidesText());
                }
                return GuidesTexts.First();  
            }

            set
            {
                if (GuidesTexts.Any())
                {
                    GuidesTexts.Clear();
                }

                GuidesTexts.Add(value);
            }
        }
    }
    
    public class Guide_Validate
    {
        [Required]
        [Display(Name = "Название гайда")]
        public string Title {get; set;}

        [Required]
        [Display(Name = "Автор")]
        public string Author {get; set;}

        [Required]
        [Display(Name = "Версия доты")]
        public string Version {get; set;}

        [Required]
        [Display(Name = "Язык")]
        public int LangId { get; set; }

        [Display(Name = "Источник")]
        [DataType(System.ComponentModel.DataAnnotations.DataType.Url)]
        public string Source { get; set; }

        [Required]
        [Display(Name="Пароль")]
        public string Password { get; set; }
    }

    [MetadataType(typeof(GuidesText_Validate))]
    public partial class GuidesText
    {
      
    }

    public class GuidesText_Validate
    {
        [Required]
        [Display(Name = "Текст гайда (html)")]
        public string Text { get; set; }
    }

    public partial class Skill
    {
        public MvcHtmlString SmallDescription
        {
            get
            {
                var tablePosition = Description.IndexOf("<table", System.StringComparison.CurrentCultureIgnoreCase);
                if (tablePosition > 0)
                {
                    return MvcHtmlString.Create(Description.Remove(tablePosition).Replace("<div", "<span").Replace("</div>", "</span>"));
                }

                return MvcHtmlString.Create(Description);
            }
        }
    }

	public partial class Topic : IPublishItem
	{

	}

	public partial class Purchase : IPublishItem
	{

	}

	public partial class Upgrade : IPublishItem
	{

	}

	public partial class Command : IPublishItem
	{

	}

    public partial class Score
    {
        [DataContract]
        public class DataInfo
        {       
            [DataMember(Name="burned")]
            public int[] Burned;
            [DataMember(Name = "map")]
            public int[] Map;
        }

        public DataInfo GetDataInfo()
        {
            var serializer = new DataContractJsonSerializer(typeof(DataInfo));          
            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(Data)))
            {
                 return serializer.ReadObject(stream) as DataInfo;
            }
        }
    }
}